package 匿名内部类;

public class Test {
    public static void main(String[] args) {
//        animal a = new dog();
//        a.cry();

        //匿名内部类
        animal a = new animal() {
            @Override
            public void cry() {
                System.out.println("猫喵喵喵的叫~~~");
            }
        };
        a.cry();
        //匿名内部类通常用于方法传参
        go(new animal() {
            @Override
            public void cry() {
                System.out.println("猫喵喵喵的叫~~~");
            }
        });

    }
    public static void go(animal s) {
        System.out.println("方法");
        s.cry();
    }
}



//平常写法
//class dog extends animal {
//
//    @Override
//    public void cry() {
//        System.out.println("狗汪汪汪的叫~~~");
//    }
//}
//class cat extends animal {
//    @Override
//    public void cry() {
//        System.out.println("猫喵喵喵的叫~~~");
//    }
//}
abstract class animal {
    abstract public void cry();

}
